package com.easyexcle.demo.easyExcel.util;

import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: lkz
 * @Title: QuarterGroup
 * @Description: 季度划分 每一天
 * @Date: 2023/5/20 14:45
 */

public class QuarterGroup {



    public static void main(String[] args) {
        LocalDate startDate = LocalDate.of(2022, Month.JULY, 1);
        LocalDate endDate = LocalDate.of(2023, Month.MARCH, 31);

        Map<String, List<LocalDate>> quarters = new HashMap<>();

        LocalDate currentDate = startDate;
        while (!currentDate.isAfter(endDate)) {
            String quarter = getQuarter(currentDate);
            if (!quarters.containsKey(quarter)) {
                quarters.put(quarter, new ArrayList<>());
            }
            quarters.get(quarter).add(currentDate);
            currentDate = currentDate.plusDays(1);
        }

        for (String quarter : quarters.keySet()) {
            System.out.println("Quarter " + quarter + ":");
            for (LocalDate date : quarters.get(quarter)) {
                System.out.println(date);
            }
        }
    }

    private static String getQuarter(LocalDate date) {
        int month = date.getMonthValue();
        if (month >= 1 && month <= 3) {
            return "Q1";
        } else if (month >= 4 && month <= 6) {
            return "Q2";
        } else if (month >= 7 && month <= 9) {
            return "Q3";
        } else {
            return "Q4";
        }
    }

}
